<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>余额提现</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>

	<body>
		<form class="layui-form update_form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">认证</label> {if $oem_info['is_verify'] == 1}
				<div class="layui-input-block update_shurk" style="line-height: 40px;align-content: center;">
					<a class='to_renzheng' href="javascript:;" style="color: #0a6ce6;">已认证</a>
				</div>
				{else}
				<div class="layui-input-block update_shurk" style="line-height: 40px;align-content: center;">
					<a class='to_renzheng' href="javascript:;" style="color: #0a6ce6;">去认证</a>
				</div>
				{/if}
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">余额</label>
				<div class="layui-input-block update_shurk">
					<input type="text" value="{$oem_info['balance']}" class="layui-input" disabled="disabled">

				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">需要提现</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="tixian_money" id='balance' onkeyup="clearNoNum(this)" required lay-verify="required" placeholder="￥" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-form-item" style="padding: 10px;">
					商家签约绑定结算银行卡后，T+1进行结算，结算费率为0；申请成功后，该笔提现会在第二个工作日24:00点之前到账。
				</div>
			</div>
			<div class="layui-form-item update_btnbox">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>
</html>
<script>
	//只能数字和小数点
	function clearNoNum(obj) {
		obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
		obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
		obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}

	$('.to_renzheng').click(function() {
		parent.location.href = "{:url('index/renzheng')}";
	})

	function to_tixian() {
		
		var is_verify = "{$oem_info['is_verify']}";
		
		var cut_balance = "{$oem_info['balance']}";
		var to_num = $('#balance').val();
		
		if(is_verify !=1){
			layer.msg("请先提交认证资料", {
					icon: 1,
					time: 1500 //2秒关闭（如果不配置，默认是3秒）
				}, function() {
					parent.location.href = "{:url('index/renzheng')}";
				});
			return ;
		}
		
		if(to_num < 95) {
			layer.msg('提现金额不能小于95！');
			return;
		}
		
		if(to_num > 10000) {
			layer.msg("单词提现金额不能超过10000元");
			return;
		}
		
		if(to_num > cut_balance) {
			layer.msg('余额不足！');
			return;
		}

		$.ajax({
			type: "post",
			url: "{:url('index/yue_tixian')}",
			data: {
				balance: $('#balance').val()
			},
			success: function(data) {
				layer.msg(data.msg, {
					icon: 1,
					time: 1500 //2秒关闭（如果不配置，默认是3秒）
				}, function() {
					parent.location.reload();
				});
			},
			error: function(data) {
				var a = data;
			}
		});
	}
	layui.use('form', function() {
		var form = layui.form;
		//监听提交
		form.on('submit(formDemo)', function(data) {
			to_tixian();
			return false;
		});
	});
</script>